#include "enum.h"
#include "mytools.h"
#include <stdio.h>

void enum_declaration() {
  print_title("enum declaration");
  {
    // enum Color; // error: missing tag name
    enum Color { RED, GREEN, BLUE };
    int color = RED;
    // 打印 color 的值
    printf("color = %d\n", color);
  }
  {
    // 结构体应用
    struct Element oxygen = {8, GAS};
    enum State e = LIQUID;
    int i = SOLID;
    printf("%d %d %d %d\n", i, e, oxygen.state, PLASMA);
  }
  {
    enum Foo { A, B, C = 10, D, E = 1, F, G = F + C };
    // A=0, B=1, C=10, D=11, E=1, F=2, G=12
  }
  {
    enum Color { RED, GREEN, BLUE };
    typedef enum Color Color_t;
    Color_t color = BLUE;

    switch (color) {
    case RED:
      puts("color is red");
      break;
    case GREEN:
      puts("color is green");
      break;
    case BLUE:
      puts("color is blue");
      break;
    default:
      break;
    }
  }
}